package com.software.levelupandroid.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.software.levelupandroid.entity.Label;
import com.software.levelupandroid.entity.Result;
import com.software.levelupandroid.entity.Task;

import java.lang.reflect.Type;
import java.util.List;

/**
 * @Description TODO
 * @Author LiangYaJie
 * @CreateTime 2024年06月03日 15:31:58
 */
public class JsonUtil {

    /**
     * 将json转换为Result<List<Task>>类型
     * @param respJson
     * @return
     */
    public static Result convertJsonToTaskList(String respJson){
        Gson gson = new Gson();
        Type type = new TypeToken<Result<List<Task>>>() {}.getType();
        Result<List<Task>> result = gson.fromJson(respJson, type);

        return result;
    }
    public static Result convertJsonToLabelList(String respJson){
        Gson gson = new Gson();
        Type type = new TypeToken<Result<List<Label>>>() {}.getType();
        Result<List<Label>> result = gson.fromJson(respJson, type);

        return result;
    }
}
